package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.ScenicFileDao;
import cn.topevery.garden.entity.po.ScenicFile;
import cn.topevery.garden.entity.query.ScenicFileQuery;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-31
 */
@Repository
public class ScenicFileDaoImpl extends BaseDaoImpl<ScenicFile> implements ScenicFileDao {
    @Override
    public <P extends DbCsp> List<ScenicFile> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<ScenicFile> listPage(ScenicFileQuery query) {
        String table = "t_scenic_file tsf";

        String columns = "tsf.*";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tsf.c_id desc");
        sqlQueryMate
                .where(true, "tsf.c_db_status", ScriptConditionEnum.Eq, 0)
        ;

        return getDataPager(sqlQueryMate, query.pageSize, query.pageIndex, ScenicFile.class);
    }

    /**
     * 描述 获取文件列表
     *
     * @param pid the pid
     * @return the list by pid
     * @author wenzhao.lin
     * @created 2021 -08-26 09:09:27
     */
    @Override
    public List<ScenicFile> getListByPid(Integer pid) {
        String table = "t_scenic_file tpc";

        String columns = "tpc.*";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns);
        sqlQueryMate
                .where(true, "tpc.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, "tpc.c_main_id", ScriptConditionEnum.Eq, pid)
        ;
        return selectList(sqlQueryMate, ScenicFile.class);
    }

    @Override
    public void deleteById(Integer id) {
        String sql = "delete from t_scenic_file where c_main_id = " + id;
        run(sql, CommandType.Text, dbCommand -> {
            dbCommand.executeNonQuery();
        });
    }
}
